﻿using System.Data;
using org.se.fs.presenter.Library;

namespace org.se.fs.presenter.View.Template
{
    public abstract class SubMenu
    {
        public event FormEvent.FormEventHandler OnAdd;
        public event FormEvent.FormEventHandler OnModify;
        public event FormEvent.FormEventHandler OnValidate;
        public event FormEvent.FormEventHandler OnError;
        public DataTable Data { get; set; }

        public virtual void Initialize() { }

        protected void TriggerAdd(FormEvent e)
        {
            if (OnAdd != null)
                OnAdd(this, e);
        }

        protected void TriggerModify(FormEvent e)
        {
            if (OnModify != null)
                OnModify(this, e);
        }

        protected void TriggerValidate(FormEvent e)
        {
            if (OnValidate != null)
                OnValidate(this, e);
        }

        protected void TriggerError(FormEvent e)
        {
            if (OnError != null)
                OnError(this, e);
        }

        protected virtual void DomainPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            //-- if you want to process data when item value was changed.
            switch (e.PropertyName)
            {
                case "":
                    //-- code goes here
                    break;
            }     
        }
  
        protected virtual void TaskOnInsert(object source, FormEvent e) { }

        protected virtual void TaskOnUpdate(object source, FormEvent e) { }
      
        protected virtual void TaskOnFetch(object source, FormEvent e) { }

        public virtual void Add() { }

        public virtual void Modify() { }

        protected virtual bool Validate()
        {
            return true;
        }

        protected virtual void SetData() { }
    }
}
